package com.example.educationplatformbackend.controller;

import com.example.educationplatformbackend.domian.illustrations.Illustration;
import com.example.educationplatformbackend.service.Impl.IllustrationService;
import com.example.educationplatformbackend.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class IllustrationController {

    @Autowired
    private IllustrationService illustrationService;

    @GetMapping("getAllIllustrations")
    public ResponseResult<List<Illustration>> getAllIllustrations() {
        List<Illustration> allIllustrations = illustrationService.getAllIllustrations();

        return ResponseResult.success(allIllustrations);
    }

    @GetMapping("getIllustration/{id}")
    public Illustration getIllustration(@PathVariable Long id) {
        return illustrationService.getIllustrationById(id);
    }

    @PostMapping("addIllustration")
    public  ResponseResult<Object> addIllustration(@RequestBody Illustration illustration) {
        illustrationService.saveOrUpdate(illustration);

        return ResponseResult.success("成功");
    }

    @PostMapping("/updateIllustrations")
    public ResponseResult<Object> updateIllustration(@RequestBody Illustration illustration) {

        illustrationService.update(illustration);
        return ResponseResult.success("更新成功");
    }

    @GetMapping("deleteIllustration/{id}")
    public ResponseResult<Object> deleteIllustration(@PathVariable Long id) {
        illustrationService.deleteIllustration(id);
        return ResponseResult.success("删除成功");
    }

}
